package com.example.back.mapper;

import com.example.back.model.User;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

@Mapper
public interface UserMapper {
    @Select("select * from user")
    List<User> findAllUser();
    @Select("select * from user where concat(account, username, phone, email) like concat('%', #{information}, '%')")
    List<User> findByInformation(String information);
    @Select("select * from user where account=#{account} limit 1")
    User findByAccount(String account);
    @Select("select * from user where phone=#{phone} limit 1")
    User findByPhone(String phone);
    @Select("select * from user where username=#{username}")
    List<User> findByUsername(String username);
    @Select("select account from user where phone=#{id}")
    String findAccountByPhone(int id);
    @Insert("insert into user(account, username, password, phone, registerDate) values(#{account}, #{username}, #{password}, #{phone}, #{registerDate})")
    Boolean addUser(String account, String username, String password, String phone, String registerDate);
    //更新用户信息
    @Update("update user set photo=#{photo} where account=#{account}")
    Boolean updatePhoto(String account, String photo);
    @Update("update user set username=#{username} where account=#{account}")
    Boolean updateUsername(String account, String username);
    @Update("update user set sex=#{sex} where account=#{account}")
    Boolean updateSex(String account, int sex);
    @Update("update user set phone=#{phone} where account=#{account}")
    Boolean updatePhone(String account, String phone);
    @Update("update user set email=#{email} where account=#{account}")
    Boolean updateEmail(String account, String email);
    @Update("update user set password=#{password} where account=#{account}")
    Boolean updatePassword(String account, String password);
    @Select("select account from user where id=#{id}")
    String findAccountByID(int id);
    @Insert("insert into user(account, password, username, sex, phone, email, registerDate) value(#{account}, #{password}, #{username}, #{sex}, #{phone}, #{email}, #{registerDate})")
    Boolean insertUser(String account, String password, String username, int sex, String phone, String email, String registerDate);
    @Delete("Delete from user where id=#{id}")
    Boolean deleteUser(int id);
    @Select("select photo from user where id=#{id}")
    String findPhotoByID(int id);
}
